package com.zzw.springcloud.controller;

import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class CustomUrlCleaner implements UrlCleaner {
    @Override
    public String clean(String originalUrl) {//资源清洗
        if (StringUtils.isBlank(originalUrl)) {
            return originalUrl;
        }
        //如果请求的接口是/member/nacos/provider/selectById 开头的, 比如 /member/nacos/provider/selectById/1,/member/nacos/provider/selectById/2
        //给sentinel 返回资源名为 /member/nacos/provider/selectById/*
        //在sentinel中对 /member/nacos/provider/selectById/* 做流控规则即可
        if (originalUrl.startsWith("/member/nacos/provider/selectById")) {
            return "/member/nacos/provider/selectById/*";
        }
        return originalUrl;
    }
}
